import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-09-17
 * Time: 21:23
 */
public class Main {
    public static void main(String []args) {
        Scanner sc = new Scanner(System.in);
        int count = 0;
        int m = sc.nextInt();
        int a = 0;
        int b = 1;
        int c = 0;
        while(true) {
            c = a+b;
            a = b;
            b = c;
            if( c > m) {
                break;
            }
        }
        if( m-a < c-m) {
            count = m-a;
        } else {
            count = c-m;
        }
        System.out.print(count);
    }
}
